<template>
  <el-dialog title="客户开卡" width="40%" :before-close="dialogClose" :visible.sync="show">
      <el-form ref="form" label-width="100px">
          <el-form-item label="选择项目">
              <el-select v-model="form.card_id" placeholder="选择项目">
                <el-option v-for="(item,index) in cardName" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
          </el-form-item>
          <el-form-item label="使用次数" style="margin-top:20px;">
              <el-input type="number" placeholder="不限次数可不填" v-model="form.num"></el-input>
          </el-form-item>
          <el-form-item label="应收金额" style="margin-top:20px;">
              <el-input type="number" placeholder="应收金额" @input="give" v-model="form.money"></el-input>
          </el-form-item>
          <el-form-item label="账户抵扣" style="margin-top:20px;">
              <el-input type="number" placeholder="账户抵扣" @input="give" v-model="form.offset_money"></el-input>
          </el-form-item>
          <el-form-item label="代金券" style="margin-top:20px;">
              <el-input type="number" placeholder="代金券" @input="give" v-model="form.give_money"></el-input>
          </el-form-item>
          <el-form-item label="实收金额" style="margin-top:20px;">
              <el-input type="number" placeholder="实收金额" v-model="form.pay_money"></el-input>
          </el-form-item>
          <div align="center" style="margin-top:20px;">
            <el-button type="primary" @click="addSubmit">确 定</el-button>
            <el-button @click="dialogClose">取 消</el-button>
          </div>
      </el-form>
  </el-dialog>
</template>
 
<script>
export default {
  name: 'addCard',
  props:['show','id','cardName'],
  data() {
    return {
        form:{}
    }
  },
  created: function(){
    
  },
  methods: {
    dialogClose:function(){
      this.$emit("func",{'key':'addCard'})
    },
    give:function(){
			if(this.form.money){
				var money = this.form.money
			}else{
				var money = 0
			}
			if(this.form.offset_money){
				var offset = this.form.offset_money
			}else{
				var offset = 0
			}
			if(this.form.give_money){
				var give = this.form.give_money
			}else{
				var give = 0
			}
			this.form.pay_money = parseFloat(money) - parseFloat(offset) - parseFloat(give)
		},
    addSubmit:function(){
      if(!this.form.money){
        this.$message.error('请填写应收金额!!');
        return;
			}
      if(!this.form.num){
        this.form.num = 9999
			}
      this.form.member_id = this.id
      this.form.oa_id = localStorage.getItem('oa_id')
      var that = this
      this.$post('manage/card/addOrder',this.form).then((res) => {
          if(res.code == 1){
            that.$message.success('开卡成功!!')
            that.$emit("func",{'key':'addCard','update':1})
          }else{
            that.$message.error(res.msg);
          }
      })
    }
  }
}
</script>
<style>

</style>